import { DynamicModule } from "@nestjs/common";
import { ConfigService } from "@config/config.service";
import { TypeOrmModule } from "@nestjs/typeorm";

/**
 * TypeORM模块注册
 * @constructor
 */
const OrmModule = (): DynamicModule => {
    const config = new ConfigService(process.env.NODE_ENV)
    return TypeOrmModule.forRoot({
        type: config['DATABASE_TYPE'],
        host: config['DATABASE_HOST'],
        port: config['DATABASE_PORT'],
        username: config['DATABASE_USER'],
        password: config['DATABASE_PASSWORD'],
        database: config['DATABASE_DB'],
        timezone: 'UTC',
        charset: 'utf8mb4',
        entities: ['./**/*.entity.js'],
        synchronize: false,
    })
}

export { OrmModule }
